home *** CD-ROM | disk | FTP | other *** search
Text File | 1993-07-11 | 3.3 KB | 168 lines | [TEXT/MPS ] |
- #
- # znew.mac -- znew for MPW
- #
- # written by Anthony C. Ard, 1993
- #
- # this script requires sed
- #
-
- set exit 0
- set check 0
- set pipe 0
- unset opt
- unset files
- set keep 0
- set res 0
- set old 0
- set new 0
- set block 1024
- # block is the disk block size (best guess, need not be exact)
-
- set warn "(does not preserve modes and timestamp)"
- set tmp "{TempFolder}"zfoo
-
- echo "hi" >"{tmp}.1"
- echo "hi" >"{tmp}.2"
-
- # check if GZIP env. variable uses -S or --suffix
- gzip -q "{tmp}".1
- set ext `files "{tmp}".1≈ | sed "s|{tmp}.1||"`
- delete -y "{tmp}".[12]≈
-
- if "{ext}" == ""
- echo "znew: error determining gzip extension."
- set exit 1
- exit 1
- end
-
- if "{ext}" == ".Z"
- echo "znew: cannot use .Z as gzip extension."
- set exit 1
- exit 1
- end
-
- unset A
- set fileno 0
-
- for arg in {Parameters}
- if "{arg}" =~ /-≈/
- set opt "{opt} {arg}"
- else
- set fileno `evaluate {fileno} + 1`
- set A "{A} {arg}"
- end
- end
-
- if {fileno} == 0
- echo "recompress .Z files into {ext} (gzip) files"
- echo usage: `echo {0} | sed 's,^.*/,,'` "[-tv9KP] file.Z…"
- echo " -t tests the new files before deleting originals"
- echo " -v be verbose"
- echo " -9 use the slowest compression method (optimal compression)"
- echo " -K keep a .Z file when it is smaller than the {ext} file"
- echo " -P use pipes for the conversion {warn}"
- set exit 1
- exit 1
- end
-
- set opt `echo "{opt}" | sed -e 's/ //g' -e 's/-//g'`
-
- if "{opt}" =~ /≈t≈/
- set check 1
- set opt "`echo {opt} | sed 's/t//g'`"
- else if "{opt}" =~ /≈K≈/
- set keep 1
- set opt "`echo {opt} | sed 's/K//g'`"
- else if "{opt}" =~ /≈P≈/
- set pipe 1
- set opt "`echo {opt} | sed 's/P//g'`"
- end
-
- if "{opt}" != ""
- set opt "-{opt}"
- end
-
- for i in {A}
- set n "`echo "{i}" | sed 's/.Z$//'`"
- if !`exists -f "{n}.Z"`
- echo "{n}.Z not found"
- set res 1
- continue
- end
- if {keep} == 1
- set old `count -c <"{n}.Z"`
- end
- if {pipe} == 1
- gzip -d <"{n}.Z" | gzip {opt} >"{n}{ext}"
- if {Status} == 0
- # Copy file attributes from old file to new one, if possible.
- else
- echo "error while recompressing {n}.Z."
- set res 1
- continue
- end
- else
- if {check} == 1
- cp "{n}.Z" "{n}.xxx" ≥Dev:Null
- if {Status} != 0
- echo "cannot backup {n}.Z"
- set res 1
- continue
- end
- end
- gzip -d "{n}.Z"
- if {Status} != 0
- if {check} == 1
- duplicate -y "{n}.xxx" "{n}.Z"
- end
- echo "error while uncompressing "{n}.Z"
- set res 1
- continue
- end
- gzip {opt} "{n}"
- if {Status} != 0
- if {check} == 1
- duplicate -y "{n}.xxx" "{n}.Z" && delete "{n}"
- echo "error while recompressing {n}"
- else
- # compress {n} (might be dangerous if disk full)
- echo "error while recompressing {n}, left uncompressed."
- end
- set res 1
- continue
- end
- end
- if {keep} == 1
- set new `count -c <"{n}{ext}"`
- end
- if {keep} == 1 && `evaluate ({old}+{block}-1)÷{block}` < ∂
- `evaluate ({new}+{block}-1)÷{block}`
- if {pipe} == 1
- delete -y "{n}{ext}"
- else if {check} == 1
- duplicate -y "{n}.xxx" "{n}.Z" && delete -y "{n}{ext}"
- else
- gzip -d "{n}{ext}" && compress "{n}" && delete -y "{n}{ext}"
- end
- echo "{n}.Z smaller than {n}{ext} -- unchanged."
- else if {check} == 1
- gzip -t "{n}{ext}
- if {Status} == 0
- delete -y "{n}.xxx" "{n}.Z"
- else
- if {pipe} == 0
- duplicate -y "{n}.xxx" "{n}.Z"
- end
- delete -y "{n}{ext}"
- echo "error while testing {n}{ext}, {n}.Z unchanged."
- set res 1
- continue
- end
- else if {pipe} == 1
- delete -y "{n}.Z"
- end
- end
-
- set exit 1
- exit {res}
-